<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <i class="el-icon-price-tag"></i>
        <span>新增/编辑</span>
        <el-button
          :disabled="disabled"
          :loading="disabled"
          style="float: right; padding: 3px 0"
          type="primary"
          @click="onSubmit"
          >保存</el-button
        >
        <el-button
          style="float: right; padding: 3px 0"
          type="text"
          @click="$router.go(-1)"
          >取消</el-button
        >
      </div>

      <!-- 表单 -->
      <el-form ref="formRef" :model="form" label-width="100px">
        <el-form-item
          label="姓名："
          prop="name"
          :rules="[{ required: true, message: '此项不能为空' }]"
        >
          <el-input v-model="form.name" placeholder="输入姓名"></el-input>
        </el-form-item>


        <el-form-item
          label="联系方式："
          prop="contact"
          :rules="[{ required: true, message: '此项不能为空' }]"
        >
          <el-input v-model="form.contact"></el-input>
        </el-form-item>


        <el-form-item label="应聘岗位：">
          <el-input v-model="form.position"></el-input>
        </el-form-item>

        <el-form-item label="信息来源">
          <el-input v-model="form.infoFrom"></el-input>
        </el-form-item>


        <el-form-item label="面试反馈">
          <el-input v-model="form.feedback"></el-input>
        </el-form-item>

        <el-form-item label="人员状态">
          <el-input v-model="form.peopleStatus"></el-input>
        </el-form-item>

      
      </el-form>

      
    </el-card>
  </div>
</template>

<script>
export default {
  props: ['id'],
  data() {
    return {
      form: {
        name: "",
        contact: "",
        school: "",
        education: "",
        position: "",
        infoFrom: "",
        email: "",
        
      },
      
      disabled: false,
    };
  },
  mounted(){
    // console.log(this.id);
    // console.log(this.$store.getters['talent/userInfo']);
    let ret = this.$store.getters['talent/userInfo'](this.id)
    // console.log(ret);
    this.form = ret[0]

  },
  methods: {
    onSubmit() {
      // console.log("submit!");
      this.$refs["formRef"].validate(async (valid) => {
        if (valid) {
          // 验证通过
          this.disabled = true;
          // alert('submit')
          // console.log('验证通过');
          // 发送ajax
          // console.log(this.$store)
          let ret = await this.$store.dispatch("talent/updateTaAction", this.form);
          console.log(2222);
          if (ret) {
           
            this.$message.success({
              message: "保存成功",
              duration: 1500,
              onClose: () => this.$router.replace("/admin/talent"),
            });
          } else {
            this.$message.error("保存失败");
          }
        } else {
          // console.log('error submit');
          this.$message.error("保存失败");
          return false;
        }
      });
    },
    
  },
};
</script>

<style lang="scss" scoped>
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 1050px;
  margin: 30px 10px;
  //    background-color: #f2f2f2;
}

.el-input {
  width: 300px;
}
.el-form {
  margin-left: 30px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  // overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  display: block;
}
.avatar-uploader-icon[data-v-0e2542b8] {
  border: 1px dashed #ccc;
}
.up {
  display: flex;
  margin-left: 70px;
  font-size: 16px;
  color: #606266;
  span {
    margin-right: 10px;
  }
}
</style>